package com.example.zxlwork.adapter;

import android.content.Context;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.zxlwork.R;
import com.example.zxlwork.object.MineGridObj;
import com.example.zxlwork.object.RecObj;

import java.util.List;

public class GridViewMineAdapter extends BaseAdapter {

    //获取上下文环境
    private Context context;
    //布局资源
    private int layoutId;
    //数据资源
    private List<MineGridObj> list;

    public GridViewMineAdapter(){

    }
    public GridViewMineAdapter(Context context, int layoutId, List<MineGridObj> list) {
        this.context = context;
        this.layoutId = layoutId;
        this.list = list;
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //1.获取布局文件对象
        View recview = LayoutInflater.from(context).inflate(layoutId,null);
        //2.获取布局文件中的控件
        TextView textView = recview.findViewById(R.id.textItem);
        ImageView imageView = recview.findViewById(R.id.imageItem);
        //3.将数据源中的数据显示到当前位置
        MineGridObj obj = list.get(position);
        //4.将数据源中的数据显示到对应控件中去
        textView.setText(obj.getStr());
        imageView.setImageResource(obj.getImage());


        return recview;




    }
}
